package org.diviner.chat01.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @author ：xuchao
 * @date ：Created in 2021/3/26 13:04
 * @description：配置websocket
 * @modified By：
 * @version: 1.0
 */
@Configuration
@EnableWebSocketMessageBroker     //开启websocket消息代理
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    /**
     * 注册端点
     * */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //定义一个前缀为chat的endpoint，并开启sockjs的支持
        registry.addEndpoint("/chat").withSockJS();
    }

    /**
     * 配置消息代理
     * */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/topic");
//        registry.setApplicationDestinationPrefixes("/app");

    }
}
